package utils

import "strconv"

func SumFloat(score []float64) int {
	var total int
	for _, f := range score {
		total += int(f)
	}
	return total
}

func SumInt(score []int) int {
	var total int
	for _, f := range score {
		total += f
	}
	return total
}

func SumSliceFlat64(collection []interface{}) int {
	var total int
	for _, i2 := range collection {
		total += int(i2.(float64))
	}
	return total
}

func GetInt(val interface{}) int {
	f, ok := val.(float64)
	if !ok {
		return 0
	}
	return int(f)
}

func GetInt64(val interface{}) int64 {
	f, ok := val.(float64)
	if !ok {
		return 0
	}
	return int64(f)
}

func GetFloat64(val interface{}) float64 {
	f, ok := val.(float64)
	if !ok {
		return 0
	}
	return f
}

func StringToFloat(val string) float64 {
	f, err := strconv.ParseFloat(val, 64)
	if err != nil {
		return 0
	}
	return f
}
func StringToInt(val string) int {
	f, err := strconv.Atoi(val)
	if err != nil {
		return 0
	}
	return f
}
